unit RegisterAutoRun;

interface

uses Classes, Registry, sysutils, windows,
     GlobalVar;

Type
  TRegisterAutoRun = class
    private
      procedure Do_RegisterAutoRun;
      Procedure Do_UnRegisterAutoRun;
    public
      procedure Execute(aRegister:Boolean);
end;

implementation

{ TAutoRun }

procedure TRegisterAutoRun.Do_RegisterAutoRun;
var
  reg: TRegistry;
begin
  reg := TRegistry.Create;
  try
    reg.RootKey := HKEY_LOCAL_MACHINE;
    reg.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Run', True);
     if AnsiCompareText('debug', Paramstr(1)) = 0 then
        reg.WriteString(PRODUCT_NAME, Paramstr(0) + ' debug' )
     else
        reg.WriteString(PRODUCT_NAME, Paramstr(0));
  finally
    reg.free;
  end;
end;

procedure TRegisterAutoRun.Do_UnRegisterAutoRun;
var
  reg: TRegistry;
begin
  reg := TRegistry.Create;
  try
    reg.RootKey := HKEY_LOCAL_MACHINE;
    reg.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Run', True);
    if reg.ValueExists(PRODUCT_NAME) then  reg.DeleteValue(PRODUCT_NAME);
  finally
    reg.free;
  end;


end;

procedure TRegisterAutoRun.Execute(aRegister: Boolean);
begin
  if aRegister then Do_RegisterAutoRun
  else Do_UnRegisterAutoRun;
end;

end.
